package com.example.transaction_springboot.mapper;

import com.example.transaction_springboot.controller.request.BaseRequest;
import com.example.transaction_springboot.controller.request.LoginRequest;
import com.example.transaction_springboot.entity.Admin;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdminMapper {

    @Select("select * from admin")
    List<Admin> listAdmins();

    @Select("select * from admin where username like concat('%',#{username},'%')" +
            "and phone like concat('%',#{phone},'%') and email like concat('%',#{email},'%') order by id desc limit #{pageNum},#{pageSize}")
    List<Admin> selectByPage(BaseRequest baseRequest);

    @Select("select COUNT(id) from admin where username like concat('%',#{username},'%')" +
            "and phone like concat('%',#{phone},'%') and email like concat('%',#{email},'%')")
    int selectCountByPage(BaseRequest baseRequest);

    @Insert("insert into admin values(NULL,#{username},#{password},#{phone},#{email},#{address},#{createtime},#{updatetime})")
    void addAdmin(Admin admin);

    @Select("select * from admin where id = #{id}")
    Admin selectById(Integer id);

    @Update("update admin set username=#{username}, phone=#{phone}, email = #{email}, address=#{address},updatetime = #{updatetime} where id=#{id}")
    void updateById(Admin admin);

    @Update("update admin set password = #{password} where id=#{id}")
    void updatePassword(Admin admin);

    @Delete("delete from admin where id = #{id}")
    void deleteById(Integer id);

    @Select("select * from admin where username = #{username} and password = #{password}")
    Admin selectByUsernameAndPassword(LoginRequest loginRequest);

    @Select("select * from admin where username = #{username}")
    Admin selectByUsername(String username);
}
